#!/bin/bash
# Master script to run all algorithm tests

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Configuration
TRACES="${TRACES:-100}"
TRACE_DELAY="${TRACE_DELAY:-500000}"

# Export for sub-scripts
export TRACES
export TRACE_DELAY

echo "========================================"
echo "Intermediate Value Models - Full Test Suite"
echo "========================================"
echo "Configuration:"
echo "  Traces: $TRACES"
echo "  Trace Delay: ${TRACE_DELAY}us"
echo ""

# Test algorithms
ALGORITHMS=(
    "aes"
    "sm4"
    "rsa"
    "ecc"
    "sm2"
    "dilithium"
)

# Parse command line arguments
if [ $# -gt 0 ]; then
    ALGORITHMS=("$@")
    echo "Running selected algorithms: ${ALGORITHMS[@]}"
else
    echo "Running all algorithms"
fi
echo ""

# Run each test
START_TIME=$(date +%s)

for algo in "${ALGORITHMS[@]}"; do
    TEST_SCRIPT="$SCRIPT_DIR/test_${algo}.sh"
    
    if [ -f "$TEST_SCRIPT" ]; then
        echo ""
        echo "════════════════════════════════════════"
        echo "Starting: $algo"
        echo "════════════════════════════════════════"
        bash "$TEST_SCRIPT"
    else
        echo "[-] Test script not found: $TEST_SCRIPT"
    fi
done

END_TIME=$(date +%s)
DURATION=$((END_TIME - START_TIME))

echo ""
echo "========================================"
echo "All Tests Complete"
echo "========================================"
echo "Total time: ${DURATION}s"
echo "Results saved to: $(dirname "$SCRIPT_DIR")/summary_results/"
echo ""
echo "Next steps:"
echo "  1. Review individual results in summary_results/"
echo "  2. Generate comparison report:"
echo "     python generate_comparison_report.py"
echo ""
